package java3_6;

import java.util.Scanner;

/**
 * 7：如果斐波拉切数列的前N项，N由用户输入。
 * 斐波拉切数列的定义是前两个是1，后面的每一个是前面的两个和
 * ，比如N是5,则输出结果是1,1,2,3,5
 */
public class homework7 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入斐波那契数列的前N项：");
        int x = scanner.nextInt();
        int a = 1;
        int b = 1;
        int c = 0;
        if (x == 1){
            System.out.println(1);
            return;
        }
        if (x == 2){
            System.out.println(1+","+1);
            return;
        }
        String result = a+","+b;
        for (int i=3;i<=x;i++){
            c = a+b;
            result = result+","+c;
            a = b;
            b = c;

        }
        System.out.println(result);
    }
}
